package si.yun.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import si.yun.dao.MicroCircleDao;
import si.yun.entity.SyBeforeUser;
import si.yun.service.MicroCircleService;
import si.yun.utils.KeyWordFilter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: 微圈分类Service层实现类
 * @Description: TODO
 * @Author: 李振海
 * @Date 2021/10/18 10:08
 */
@Service("MicroCircleServiceImpl")
@Slf4j
public class MicroCircleServiceImpl implements MicroCircleService {

    @Autowired
    private MicroCircleDao microCircleDao;

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 获取微圈分类数据
     * @Date 2021/10/13 13:52
     **/
    @Override
    public List<Map<String, Object>> selForumClass() {
        List<Map<String, Object>> ForumClass = microCircleDao.selForumClass();
        return ForumClass;
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 通过微圈分类id获取该微圈分类下的数据
     * @Date 2021/10/13 13:52
     **/
    @Nullable
    @CacheEvict(value = "InfoList", key = "#id")
    @Override
    public List<Map<String, Object>> selMicrocircleDetailsList(int id) {
        List<Map<String, Object>> selMicrocircleDetailsList = microCircleDao.selForum(id);
        return selMicrocircleDetailsList;
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 通过微圈id获取微圈详情页面的具体信息
     * @Date 2021/10/13 13:52
     **/
    @Override
    public Map<String, Object> selMicrocircleDetails(Integer id) {
        //点击文章时该文章的点击量增加1
        int updMicrocircleDetails = microCircleDao.updMicrocircleDetails(id);
        //通过文章的id获取该文章相对应的详情数据
        Map<String, Object> MicrocircleDetails = microCircleDao.selMicrocircleDetails(id);
        //将发布时间格式进行处理
        String release_time = MicrocircleDetails.get("release_time").toString();
        String t = release_time.replace("T", " ");
        MicrocircleDetails.put("release_time", t);
        if (updMicrocircleDetails != 0) {
            return MicrocircleDetails;
        }
        return null;
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 通过微圈id获取该微圈下相对应的评论
     * @Date 2021/10/13 13:52
     **/
    @Override
    public List<Map<String, Object>> selCommentData(Integer id) {
        List<Map<String, Object>> Comment = microCircleDao.selCommentData(id);
        return Comment;
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 对当前微圈进行评论
     * @Date 2021/10/13 13:52
     **/
    @Override
    public int addComment(Map<String, Object> map) {
        String value = (String) map.get("value");
        KeyWordFilter.initPattern();
        //通过工具类匹配评论内容是否包含敏感词，如果有敏感词会以*进行代替
        String s = KeyWordFilter.doFilter2(value);
        map.put("value", s);
        return microCircleDao.addComment(map);
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 判断当前登录的用户是否已经收藏查看的微圈
     * @Date 2021/10/13 13:52
     **/
    @Override
    public Map<String, Object> selCollection(Map<String, Object> map) {
        Map<String, Object> map1 = new HashMap<>();
        int selFabulous = microCircleDao.selFabulous(map, 4);
        int stringObjectMap = microCircleDao.selCollection(map, 4);
        map1.put("fabulous", selFabulous);
        map1.put("collection", stringObjectMap);
        return map1;
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 当前登录用户收藏此条微圈
     * @Date 2021/10/13 13:52
     **/
    @Override
    public int addCollection(Map<String, Object> map) {
        return microCircleDao.addCollection(map);
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 当前登录用户取消收藏此条微圈
     * @Date 2021/10/13 13:52
     **/
    @Override
    public int DelCancelCollection(Map<String, Object> map) {
        return microCircleDao.DelCancelCollection(map);
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 当前登录用户取消点赞此条微圈
     * @Date 2021/10/13 13:52
     **/
    @Override
    public int DelFabulous(Map<String, Object> map) {
        int i = microCircleDao.DelFabulous(map);
        int i1 = microCircleDao.DelFabulous1(map);
        return i + i1;
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 当前登录用户点赞此条微圈
     * @Date 2021/10/13 13:52
     **/
    @Override
    public int addFabulous(Map<String, Object> map) {
        int i = microCircleDao.addFabulous(map, 4);
        int i1 = microCircleDao.addFabulous1(map);
        return i + i1;
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 获取该微圈分类下相关的推荐
     * @Date 2021/10/13 13:52
     **/
    @Override
    public List<Map<String, Object>> selRecommend(Integer id) {
        List<Map<String, Object>> maps = microCircleDao.selRecommend(id);
        return maps;
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 获取微圈分类数据
     * @Date 2021/10/13 13:52
     **/
    @Override
    public List<String> selReleaseMicroClassData() {
        return microCircleDao.selReleaseMicroClassData();
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 发布微圈
     * @Date 2021/10/13 13:52
     **/
    @Override
    public int addReleaseMicroData(Map<String, Object> map) {
        //通过微圈名称获取为id
        int classId = microCircleDao.selClassId((String) map.get("className"));
        //将微圈分类的id添加到数据中
        map.put("classId", classId);
        int ReleaseMicroData = microCircleDao.addReleaseMicroData(map);
        return ReleaseMicroData;
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 将搜索内容去和搜索关键字进行匹配，如果相匹配搜索关键字表的搜索次数加1
     * @Date 2021/10/13 13:52
     **/
    @Override
    public int selEsData(String content) {
        //将搜索的内容在数据库中进行匹配，如果存在就将id进行返回，返回后将其搜索次数+1
        Integer m = microCircleDao.selEsData(content);
        int i = 0;
        if (m != null)
            i = microCircleDao.updEsData(m);
        return i;
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 获取热门搜索记录
     * @Date 2021/10/13 13:52
     **/
    @Override
    public List<Map<String, Object>> selPopularSearch() {
        return microCircleDao.selPopularSearch();
    }

    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 修改微圈
     * @Date 2021/10/13 13:52
     **/
    @Override
    public int updReleaseMicroData(Map<String, Object> map) {
        int classId = microCircleDao.selClassId((String) map.get("className"));
        //将微圈分类的id添加到数据中
        map.put("classId", classId);
        int ReleaseMicroData = microCircleDao.updReleaseMicroData(map);
        return ReleaseMicroData;
    }
    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description 微圈分享数量+1
     * @Date 2021/10/13 13:52
     **/
    @Override
    public Integer addMicroCircleSharing(Integer id) {

        return microCircleDao.addMicroCircleSharing(id);
    }
    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description  删除个人评论 更改状态为删除
     * @Date 2021/10/13 13:52
     **/
    @Override
    public Integer updCommentStatusDelwq(Integer commentId, Integer userId, Integer commodityId) {
        return  microCircleDao.updCommentStatusDelwq(commentId,userId,commodityId);
    }
    /**
     * @return java.lang.List<Map       <       String       ,       Object>>
     * @Description  评论点赞
     * @Date 2021/10/13 13:52
     **/
    @Override
    public Integer addDetailsLike(Integer commentId) {

        return   microCircleDao.addDetailsLike(commentId);
    }
}


